package springinpractice.ch8.news.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import springinpractice.ch8.news.service.NewsService;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

@Controller
public final class NewsController {
	private NewsService newsService;
	private String rssNewsFeedView;
	
	
	// ========================================================================
	// Dependency injection methods
	// ========================================================================
	
	@Required
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	
	@Required
	public void setRssNewsFeedView(String rssNewsFeedView) {
		this.rssNewsFeedView = rssNewsFeedView;
	}
	
	
	// ========================================================================
	// Service methods
	// ========================================================================
	
	@RequestMapping("/news/rss.do")
	public String rss(HttpServletResponse res, Model model) {
		model.addAttribute(newsService.getRecentNews());
		return rssNewsFeedView;
	}
}
